﻿using Sword.Data;
using Sword.ProxyCore;
using Sword.WorkBench;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace websword.firewall
{
    static class Program
    {

        static CoreService coreService = null;


        [DllImport("kernel32.dll")]
        public static extern Boolean AllocConsole();
        [DllImport("kernel32.dll")]
        public static extern Boolean FreeConsole();
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            //AllocConsole();
            Console.Write("fds");
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());





            coreService = new CoreService()
            {
                CallbackUpdateMessage = UpdateMessage,
                CallbackWarning = WarningMessage,
                StartCompleted = StartCompletedCallback,
                StopCompleted = StopCompletedCallback,
                RulesLoadCompleted = RulesLoadCompleted
            };


            Server.start();

            coreService.Start();







            if (false)
            {
                FreeConsole();

                coreService.ShutDown();

                if (Fiddler.FiddlerApplication.oProxy != null)
                {
                    Fiddler.FiddlerApplication.oProxy.Detach();
                }
                Fiddler.URLMonInterop.ResetProxyInProcessToDefault();

                Fiddler.FiddlerApplication.Shutdown();
            }
        }



        static void UpdateMessage(string message)
        {
            //Console.WriteLine(string.Format("[{0}] {1}", DateTime.Now.ToString("MM-dd HH:mm:ss.fff"), message));
        }

        static void WarningMessage(string message)
        {
            //Console.WriteLine(string.Format("[{0}] {1}", DateTime.Now.ToString("MM-dd HH:mm:ss.fff"), message));
        }
        static void StartCompletedCallback()
        {

        }

        static void StopCompletedCallback()
        {

        }


        static void RulesLoadCompleted(List<ConditionItem> rules)
        {
            //this.rules.Clear();
            //this.rules.AddRange(rules);
        }
    }
}
